package com.khalil.kkadmin.module.quicklink.service;

import com.khalil.kkadmin.common.exception.BusinessException;
import com.khalil.kkadmin.common.exception.ExceptionEnum;
import com.khalil.kkadmin.common.util.JsonUtil;
import com.khalil.kkadmin.infrastructure.BaseService;
import com.khalil.kkadmin.module.quicklink.domain.QuickLinkGroup;
import com.khalil.kkadmin.module.quicklink.domain.QuickLinkGroupRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuickLinkGroupServiceImpl extends BaseService<QuickLinkGroupRepository, QuickLinkGroup, Long> implements QuickLinkGroupService {

    public QuickLinkGroupServiceImpl(QuickLinkGroupRepository repository) {
        super(repository);
    }

    @Override
    protected QuickLinkGroup str2CreateEntity(String json) {
        QuickLinkGroup quickLinkGroup = JsonUtil.parseJson2Object(json, QuickLinkGroup.class);
        quickLinkGroup.setId(null);
        return quickLinkGroup;
    }

    @Override
    protected QuickLinkGroup str2UpdateEntity(String json) {
        QuickLinkGroup updated = JsonUtil.parseJson2Object(json, QuickLinkGroup.class);
        QuickLinkGroup quickLinkGroup = repository.findById(updated.getId()).orElse(null);
        if (quickLinkGroup == null) {
            throw new BusinessException(ExceptionEnum.NOT_FOUND, "QuickToolGroup not found");
        }
        quickLinkGroup.setName(updated.getName());
        return quickLinkGroup;
    }

    @Override
    public List<QuickLinkGroup> list(String params) {
        return List.of();
    }
}
